Skip to content

Add sparse stack#2014

Open
cflinto wants to merge 14 commits into
feat/rand-developfrom
feat/rand-develop-poc
Open

Add sparse stack#2014
cflinto wants to merge 14 commits into
feat/rand-developfrom
feat/rand-develop-poc

Conversation

@cflinto
Copy link
Copy Markdown

@cflinto cflinto commented May 4, 2026

Add SparseStack class, using the same logic as CountSketch and gaussian.
No concerns for optimization yet.

@cflinto
Copy link
Copy Markdown
Author

cflinto commented May 4, 2026

I see the spell check failed, will work on it.

Copy link
Copy Markdown
Member

@yhmtsai yhmtsai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly format, but try to go through the code

Comment thread core/device_hooks/common_kernels.inc.cpp
Comment thread omp/sketch/sparse_stack_kernels.cpp
Comment thread omp/sketch/sparse_stack_kernels.cpp Outdated
Comment thread omp/sketch/sparse_stack_kernels.cpp
Comment thread omp/sketch/sparse_stack_kernels.cpp
Comment thread include/ginkgo/core/sketch/sparse_stack.hpp Outdated
Comment thread include/ginkgo/core/sketch/sparse_stack.hpp Outdated
Comment on lines +54 to +56
static std::unique_ptr<SparseStack> create(
std::shared_ptr<const Executor> exec, size_type sketch_size,
size_type input_size, size_type zeta, uint64 seed);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you will also need create with executor for default contruction

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean static std::unique_ptr<SparseStack> create(std::shared_ptr<const Executor> exec)

Comment thread omp/sketch/sparse_stack_kernels.cpp Outdated
Comment on lines +26 to +27
* Each input row i is mapped to zeta output rows hash_map[i * zeta + z]
* with signs signs[i * zeta + z] for z in [0, zeta).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is zeta in the "zeta output rows" the same meaning as i * zeta + z?
the operation is not complex, but does any initial paper provide it?

Copy link
Copy Markdown
Member

@pratikvn pratikvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I think we can probably merge this as soon as you add some tests (See core/test/*_sketch_kernels.cpp).

We can focus on getting the functionality in and benchmarking it, as we are not really merging it into develop yet.

*
* Each input row i is mapped to zeta output rows hash_map[i * zeta + z]
* with signs signs[i * zeta + z] for z in [0, zeta).
* Only O(zeta * m) storage is needed (no explicit matrix).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also mention how it is different (possible advantages) to CountSketch ?

Comment thread core/sketch/sparse_stack.cpp
Comment thread reference/sketch/sparse_stack_kernels.cpp
Comment thread omp/sketch/sparse_stack_kernels.cpp
cflinto and others added 12 commits May 8, 2026 15:47
Co-authored-by: Yu-Hsiang M. Tsai <19565938+yhmtsai@users.noreply.github.com>
Co-authored-by: Yu-Hsiang M. Tsai <19565938+yhmtsai@users.noreply.github.com>
Co-authored-by: Yu-Hsiang M. Tsai <19565938+yhmtsai@users.noreply.github.com>
Co-authored-by: Yu-Hsiang M. Tsai <19565938+yhmtsai@users.noreply.github.com>
Co-authored-by: Yu-Hsiang M. Tsai <19565938+yhmtsai@users.noreply.github.com>
Co-authored-by: Yu-Hsiang M. Tsai <19565938+yhmtsai@users.noreply.github.com>
@cflinto
Copy link
Copy Markdown
Author

cflinto commented May 12, 2026

The most important issues should be resolved now, maybe we can merge and focus on the remaining issues later?

Comment thread core/test/sketch/sparse_stack.cpp Outdated
// Added zeta = 1
auto sketch = TestFixture::Sketch::create(this->exec, 3, 5, 1, 42);
auto b = Dense::create(this->exec, gko::dim<2>{4, 5});
// x must have rows == 3 (sketch_size), this has 4
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here, // x must have rows == b->rows (4) ? This test seems to pass now, as the dimension of x is actually correct.

@pratikvn
Copy link
Copy Markdown
Member

I think there is an issue with the test: https://gitlab.com/ginkgo-project/ginkgo-public-ci/-/jobs/14328574363#L4481. See review comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants